package engine;

import java.util.LinkedList;
import java.util.List;

import model.Point;
import model.Segment;
import tools.Debug;
import tools.IOManager;
import tools.ResultHolder;

public class Main {

	public static void main(String[] args) {
		if(args.length != 1){
			Debug.err("Usage: java Main dataFile");
		}
		String dataFile = args[0];
		
		IOManager iom = new IOManager();
		List<Point> points = new LinkedList<Point>();
		List<Segment> segments = new LinkedList<Segment>();
		iom.readInput(dataFile, points, segments);
		
		Point lookPoint = null;
		List<Point> pointsTmp = new LinkedList<Point>();
		//find point to be found
		for(Segment s: segments){
			pointsTmp.add(s.left);
			pointsTmp.add(s.right);
		}
		for(Point p: points){
			if(!pointsTmp.contains(p)){
				lookPoint = p;
				break;
			}
		}

		Debug.println("Segments: " + segments.size());
		Debug.println("Point to be found " + lookPoint.x + "," + lookPoint.y);
		
		ResultHolder rh = new ResultHolder(iom);
		TrapezoidalMap tm = new TrapezoidalMap(rh);
		
		rh.lookout = lookPoint;
		
		tm.createMap(segments.toArray(new Segment[segments.size()]), segments.size());
		tm.findPoint(lookPoint);
		
		Debug.println("Point is located in: " + rh.getTrapezoid().name);
		
	}
}
